#include "Crosshair.h"

Crosshair::Crosshair(/*Vehicle &v*/)
{
	//g.loadImage(".//binaarit//crosshair.bmp",&chImg,0,255,0);
	chImg = g.getNSChImg();
	
	hidden.x =0;
	hidden.y =0;
	hidden.w =1;
	hidden.h =1;
	
	visible.x =0;
	visible.y =0;
	visible.w =16;
	visible.h =16;  
	
	imgObject = new ImageObject();
	imgObject->img =chImg;
}

Crosshair::~Crosshair()
{
	SDL_FreeSurface(chImg);
	delete imgObject;
}

ImageObject* Crosshair::getImageObject()
{
	imgObject->leftUpperCorner.x = x;
	imgObject->leftUpperCorner.y = y;
	return imgObject;
}

void Crosshair::calculatePosition(float angle, int speed, int px, int py)
{
	angle = (angle*PI)/180; //muutos radiaaneihin
	x= px +(speed * cos(angle));
	y= py -(speed * sin(angle));
}

void Crosshair::setVisible(bool isVisible)
{
	if(isVisible)
		SDL_SetClipRect(chImg, &visible );
	else
		SDL_SetClipRect(chImg, &hidden );	
}
